<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标绑定</title>
    <style>
        #ball{
            width: 80px;
            height: 80px;
            background: lightblue;
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="ball"></div>

    <script>
        //获取方块元素
        var ball = document.querySelector('#ball')
        //鼠标在文档移动执行操作
        document.onmousemove=function(ev){
            //控制方块位置
            ball.style.left= ev.clientX  + 'px'
            ball.style.top= ev.clientY  + 'px'
        }
    </script>
</body>
</html>